<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import resize from '@/mixins/resize'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'rose'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '100px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = this.$echarts.init(this.$el)

      this.chart.setOption({
        title: {
          text: '温室气体排放占比',
          x: 'center',
          top: '8%',
          textStyle: {
            fontSize: 12,
            color: '#fff'
          }
        },
        color: [
          '#37a2da',
          '#32c5e9',
          '#9fe6b8',
          '#ffdb5c',
          '#ff9f7f',
          '#fb7293',
          '#e7bcf3',
          '#8378ea'
        ],
        tooltip: {
          trigger: 'item',
          formatter: '{b} : {d}%',
          position: 'right'
        },
        legend: {
          bottom: 2,
          itemHeight: 10,
          itemWidth: 10,
          icon: 'circle',
          textStyle: {
            color: '#fff'
          }
        },
        series: [
          {
            name: '温室气体排放占比',
            type: 'pie',
            radius: [10, 50],

            roseType: 'area',
            data: [
              { value: 75, name: 'CO2' },
              { value: 16, name: 'CH4' },
              { value: 6, name: 'NO2' },
              { value: 2, name: 'HFCs' },
              { value: 2, name: 'PFCs' },
              { value: 2, name: 'SF6' }
            ],
            labelLine: {
              show: true,
              length: 5,
              length2: 10,
              // smooth: true,
              lineStyle: {
                color: '#999',
                width: 1,
                type: 'solid'
              }
            }
          }
        ]
      })
    }
  }
}
</script>
